
  
#send DTMF  
def dtmf_by_info_outbound_EXTDN_1():
  """ Outbound call to ExtDN1,answer.DN1 release """
  DN2.MakeCall(ExtDN1, userData = {"outbound_EXTDN_1": "Outbound call to ExtDN1,answer.DN1 release"})
  ExtDN1.AnswerCall()
  DN2.SendDTMF(digits = '123456')
  time.sleep(5)
  DN2.ReleaseCall()  
  
# Monitor next call 
def inbound_cdn_dn_OneCall_Normal_Agent_01():
  DN4.MonitorNextCall(DN1, MonitorNextCallType.MonitorOneCall, extensions = {"MonitorMode": "normal", "MonitorScope": "agent"})
  ExtDN1.MakeCall(CDN1)
  CDN1.RouteCall(DN1)
  DN1.AnswerCall()
  DN4.AnswerCall()
  ExtDN1.ReleaseCall()

def inbound_cdn_dn_OneCall_Normal_Agent_02():
  DN4.MonitorNextCall(DN1, MonitorNextCallType.MonitorOneCall, extensions = {"MonitorMode": "normal", "MonitorScope": "agent"})
  ExtDN1.MakeCall(CDN1)
  CDN1.RouteCall(DN1)
  DN1.AnswerCall()
  DN4.AnswerCall()
  DN1.ReleaseCall()
  
  
#Alternate and treatment
def inbound_DN_transfer_DN_alternate_1():
  """Inbound call to DN2,answer,DN2 2step xfer to DN3,answer, """
  ExtDN1.MakeCall(DN2)
  c_orig = DN2.AnswerCall()
  c_cons = DN2.InitiateTransfer(DN3)
  DN3.AnswerCall()
  DN2.AlternateCall(c_orig, c_cons)
  time.sleep(2)
  DN2.AlternateCall(c_cons, c_orig)
 
  time.sleep(1)
  DN2.CompleteTransfer()
  time.sleep(1)
  ExtDN1.ReleaseCall() 
  
def inbound_DN_transfer_DN_alternate_2():
  """Inbound call to DN2,answer,DN2 2step xfer to DN3,answer, """
  ExtDN1.MakeCall(DN2)
  c_orig = DN2.AnswerCall()
  c_cons = DN2.InitiateTransfer(DN3)
  DN3.AnswerCall()
  DN2.AlternateCall(c_orig, c_cons)
  time.sleep(2)
  DN2.AlternateCall(c_cons, c_orig)
  time.sleep(1)
  DN2.CompleteTransfer()
  time.sleep(1)
  DN3.ReleaseCall()   
  
  

def treat_inbound_CDN_dn_transfer_DN_alternate_by_hold_1():
  """Inbound call to DN2,answer,DN2 2step xfer to DN3,answer, """
  ExtDN1.MakeCall(CDN1)
  CDN1.ApplyTreatment(treatmentType = TreatmentType.PlayAnnouncement,parameters = {'LANGUAGE':  'English(US)',
        'PROMPT':               {'1':{'INTERRUPTABLE': 1, 'ID': 1}}
    })
  CDN1.RouteCall(DN2, routeType = RouteType.Unknown)
  c_orig = DN2.AnswerCall()
  c_cons = DN2.InitiateTransfer(DN3)
  DN3.AnswerCall()
  DN2.HoldCall(call = c_cons)
  DN2.RetrieveCall(call = c_orig)
  time.sleep(2)
  DN2.HoldCall(call = c_orig)
  DN2.RetrieveCall(call = c_cons)
  time.sleep(1)
  DN2.CompleteTransfer()
  time.sleep(1)
  ExtDN1.ReleaseCall() 
  
def treat_inbound_CDN_dn_transfer_DN_alternate_by_hold_2():
  """Inbound call to DN2,answer,DN2 2step xfer to DN3,answer, """
  ExtDN1.MakeCall(CDN1)
  CDN1.ApplyTreatment(treatmentType = TreatmentType.PlayAnnouncement,parameters = {'LANGUAGE':  'English(US)',
        'PROMPT':               {'1':{'INTERRUPTABLE': 1, 'ID': 1}}
    })
  CDN1.RouteCall(DN2, routeType = RouteType.Unknown)
  c_orig = DN2.AnswerCall()
  c_cons = DN2.InitiateTransfer(DN3)
  DN3.AnswerCall()
  DN2.HoldCall(call = c_cons)
  DN2.RetrieveCall(call = c_orig)
  time.sleep(2)
  DN2.HoldCall(call = c_orig)
  DN2.RetrieveCall(call = c_cons)
  time.sleep(1)
  DN2.CompleteTransfer()
  time.sleep(1)
  DN3.ReleaseCall() 
 
#treatment

def treat_music_internal_DN_conference_CDN_cdn_1():
  """Internal call to DN2,DN2 conference to CDN1, Music treat applied, route to CDN2,route to DN3, answer,complete. DN2,DN1 release"""
  DN1.MakeCall(DN2)
  DN2.AnswerCall()
  DN2.InitiateConference(CDN1, userData = {"treat_music_internal_DN_conference_CDN_cdn_1": "Internal call to DN2,DN2 conference to CDN1, Music treat applied, route to CDN2,route to DN3, answer,complete. DN2,DN1 release"})
  CDN1.ApplyTreatment(treatmentType = TreatmentType.Music,parameters = {"MUSIC_DN": "music/in_queue","DURATION":120})
  CDN1.RouteCall(CDN2, routeType = RouteType.Unknown)
  CDN2.ApplyTreatment(treatmentType = TreatmentType.Busy)
  CDN2.RouteCall(DN3, routeType = RouteType.Unknown)
  DN3.AnswerCall()
  DN2.CompleteConference()
  DN2.ReleaseCall()
  DN1.ReleaseCall()  
  
def treat_music_internal_DN_2step_transfer_CDN_dn_1():
  """Internal call DN2,xfer to CDN1, Music treat applied, route to DN3,answer,complete,DN1 release """
  DN1.MakeCall(DN2)
  DN2.AnswerCall()
  DN2.InitiateTransfer(CDN1, userData = {"treat_music_internal_DN_2step_transfer_CDN_dn_1": "Internal call DN2,xfer to CDN1, Music treat applied, route to DN3,answer,complete,DN1 release "})
  CDN1.ApplyTreatment(treatmentType = TreatmentType.Music,parameters = {"MUSIC_DN": "music/in_queue","DURATION":120})
  CDN1.RouteCall(DN3, routeType = RouteType.Unknown)
  DN3.AnswerCall()
  DN2.CompleteTransfer()
  DN1.ReleaseCall()
  
# registration
def registration_internal_DN_reg_1():
  """Internal call to DN2,answer.DN2 release"""
  DN1.MakeCall(DN2, userData = {"registration_internal_DN_reg_1": "Internal call to DN2,answer.DN2 release"})
  DN2.AnswerCall()
  DN1.RegisterAddress()
  DN1.QueryAddress()
  DN2.RegisterAddress()
  DN2.QueryAddress()
  DN2.ReleaseCall()  

# SSC

def internal_DN_single_step_conference_DN_1():
  """Internal call DN2,single step conference to DN3,answer.DN1,DN3 release """
  DN1.MakeCall(DN2)
  DN2.AnswerCall()
  DN2.SingleStepConference(DN3, userData = {"internal_DN_single_step_conference_DN_1": "Internal call DN2,single step conference to DN3,answer.DN1,DN3 release "})
  DN3.AnswerCall()
  DN1.ReleaseCall()
  DN3.ReleaseCall()
  
def internal_DN_single_step_conference_DN_2():
  """Internal call to DN2,single step conference to DN3,answer.DN2,DN3 release"""
  DN1.MakeCall(DN2)
  DN2.AnswerCall()
  DN2.SingleStepConference(DN3, userData = {"internal_DN_single_step_conference_DN_2": "Internal call to DN2,single step conference to DN3,answer.DN2,DN3 release "})
  DN3.AnswerCall()
  DN2.ReleaseCall()
  DN3.ReleaseCall()
  
# SST 
def internal_DN_single_step_transfer_DN_2():
  """Internal call to DN2,single_step xfer to DN3,answer,DN3 release"""
  DN1.MakeCall(DN2)
  DN2.AnswerCall()
  DN2.SingleStepTransfer(DN3, userData = {"internal_DN_single_step_transfer_DN_2": "Internal call to DN2,single_step xfer to DN3,answer,DN3 release "})
  DN3.AnswerCall()
  DN3.ReleaseCall()
  
def internal_DN_single_step_transfer_DN_3():
  """Internal call to DN2,single_step xfer to DN3.DN1 release """
  DN1.MakeCall(DN2)
  DN2.AnswerCall()
  DN2.SingleStepTransfer(DN3, userData = {"internal_DN_single_step_transfer_DN_3": "Internal call to DN2,single_step xfer to DN3.DN1 release"})
  DN1.ReleaseCall()  
  
  
# DeleteFromConference

def internal_DN_single_step_conference_delete_DN_1():
  """Internal call DN2,single step conference to DN3,answer.DN1,DN3 release """
  DN1.MakeCall(DN2)
  DN2.AnswerCall()
  DN2.SingleStepConference(DN3, userData = {"internal_DN_single_step_conference_DN_1": "Internal call DN2,single step conference to DN3,answer.DN1,DN3 release "})
  DN3.AnswerCall()
  DN1.DeleteFromConference(DN3)
  DN2.ReleaseCall()  
  
#Reconnect  
def inb_ExtD1_dial_D2_D2ans_D2_intran_D3_D3ans_D2reconn_ExtD1rs():
  """Inbound call to DN2,answer,DN2 2step xfer to DN3,answer,DN2 reconnect,Ext1DN1 release """
  Ext1DN1.MakeCall(DN2, userData = {"inbound_DN_reconnect_DN_1": "Inbound call to DN2,answer,DN2 2step xfer to DN3,answer,DN2 reconnect,Ext1DN1 release "})
  DN2.AnswerCall()
  DN2.InitiateTransfer(DN3)
  DN3.AnswerCall()
  DN2.ReconnectCall() 
  Ext1DN1.ReleaseCall()   